package com.ruoyi.service.impl;

import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import cn.hutool.core.io.FileUtil;
import com.ruoyi.DTO.DdtPicDTO;
import com.ruoyi.Query.DdtPicQuery;
import com.ruoyi.VO.DdtPicVO;
import com.ruoyi.mapper.pic.DdtPicMapper;
import com.ruoyi.service.pic.IDdtPicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.domain.DdtPic;

/**
 * 图片资源明细Service业务层处理
 * 
 * @author 张书林
 * @date 2025-06-22
 */
@Service
@Slf4j
public class DdtPicServiceImpl implements IDdtPicService
{
    @Autowired
    private DdtPicMapper ddtPicMapper;

    /**
     * 查询图片资源明细
     * 
     * @param id 图片资源明细主键
     * @return 图片资源明细
     */
    @Override
    public DdtPic selectDdtPicById(Long id)
    {
        return ddtPicMapper.selectDdtPicById(id);
    }

    /**
     * 查询图片资源明细列表
     * 
     * @param ddtPic 图片资源明细
     * @return 图片资源明细
     */
    @Override
    public List<DdtPic> selectDdtPicList(DdtPic ddtPic)
    {
        return ddtPicMapper.selectDdtPicList(ddtPic);
    }

    /**
     * 新增图片资源明细
     * 
     * @param ddtPic 图片资源明细
     * @return 结果
     */
    @Override
    public int insertDdtPic(DdtPic ddtPic)
    {
        return ddtPicMapper.insertDdtPic(ddtPic);
    }

    /**
     * 修改图片资源明细
     * 
     * @param ddtPic 图片资源明细
     * @return 结果
     */
    @Override
    public int updateDdtPic(DdtPicVO ddtPic)
    {
        return ddtPicMapper.updateDdtPic(ddtPic);
    }

    /**
     * 批量删除图片资源明细
     * 
     * @param ids 需要删除的图片资源明细主键
     * @return 结果
     */
    @Override
    public int deleteDdtPicByIds(Long[] ids,String picUrl)
    {
        String picPath = picUrl.replace("https://abiaoqing.com", "");
        int count = ddtPicMapper.deleteDdtPicByIds(ids);
        log.info("删除数据成功：{}",picPath);
        FileUtil.del(new File(picPath));
        log.info("删除文件成功：{}",picPath);
        return count;
    }

    /**
     * 删除图片资源明细信息
     * 
     * @param id 图片资源明细主键
     * @return 结果
     */
    @Override
    public int deleteDdtPicById(Long id)
    {
        return ddtPicMapper.deleteDdtPicById(id);
    }

    @Override
    public void inserList(List<DdtPic> ddtPicList) {
        ddtPicMapper.insertList(ddtPicList);
    }

    @Override
    public List<DdtPicDTO> list(DdtPicQuery ddtPicQuery) {
        List<DdtPicDTO> picList = ddtPicMapper.selectPicList(ddtPicQuery);
        return picList;
    }

}
